package com.sc.reducer;

import java.io.IOException;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.sc.bean.Spend;

/**
 * 
 * @Description TODO
 * @author pengjun
 * @version v1.0
 * @date 2020年7月9日
 * 
 */
public class StaffComputeReducer extends Reducer<Text, FloatWritable, Text, Spend> {

	//优化代码
	Spend spend = new Spend();
	FloatWritable moneyf = new FloatWritable();
	
	@Override
	protected void reduce(Text arg0, Iterable<FloatWritable> arg1,
			Reducer<Text, FloatWritable, Text, Spend>.Context arg2) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		float money = 0;
		for (FloatWritable m : arg1) {
			money += m.get();
		}
		spend.setName(arg0);
		moneyf.set(money);
		spend.setMoney(moneyf);
		arg2.write(arg0, spend);
	}
}
